<?php
include_once("include/include.php.inc");
html_header("Support admin");

if(isset($_POST['action']) and $_POST['action'] == 'Send'){
//	$ret = reg_check_data($_POST);
  
if(!$_POST["username"] || !$_POST["password"] || !$_POST["mail"])
  {
  echo "<center></h3>You must fill all the fields</center></h3><br />";
  }

if(!$lol=valid_email($_POST['mail'])){
     echo "<center><h3>You must enter a valid email address</center></h3><br />";
  }

else{
   
  $ret=true;
	if($ret) 
  $status = reg_adduser($_POST) ;
  else
  $status = REG_ERRORS;
	
  /* DEBUG
  echo "ret: $ret";
  echo "<br>";
  echo "status: $status";
  echo "<br>";
  */
	switch($status){
		case REG_ERRORS:
			?>
			<span class="style1">Errors detected:</span><br>
			<?php
			foreach($ret as $error)
				printf("<b>%s</b>: %s<br>", $error[0], $error[1]);
			?>
			<?php
		break;
		case REG_FAILED:
			echo "Operation failed";
		break;
		case REG_SUCCESS:
			echo "<center><h3>User ".$_POST["username"]." Added!</center></h3>";
		break;
	}
}}

/*   $backlink=getenv('HTTP_REFERER');*/

   $result = mysql_query( "SELECT * FROM ssts_support" );
          // or die("SELECT Error: ".mysql_error());

           $num_rows = mysql_num_rows($result);

echo "<div class='box'>\n"; 
echo " <div class='boxtop'><div></div></div>\n"; 
echo "  <div class='boxcontent'>\n"; 

           print "<TABLE width=\"100%\" bgcolor=\"#336699\" BORDER=\"0\" bordercolor=\"#FFFFFF\"><tr>";
          // print "<th width=\"11%\" scope=\"col\"><span class=\"style6\">No.</span></th>";
		   print "<th width=\"42%\" scope=\"col\"><span class=\"style6\">Name</span></th>";
		   print "<th width=\"48%\" scope=\"col\"><span class=\"style6\">Email</span></th>";
		   print "<th width=\"5%\" scope=\"col\"></th>";
		   print "<th width=\"5%\" scope=\"col\"></tr>";

           while ($row = mysql_fetch_assoc($result)){
                 extract($row);
		     	// print "<tr><td> $sup_no</td>";
		     	 print "<td>$sup_name</td>";
		     	 print "<td>$sup_email</td>";
                 print "<td><a href=\"del_support.php?cmd=del&sup_uid=$sup_uid\"><IMG src=\"css/images/del.gif\"></a></td>";
                 print "<td><a href=\"edit_support.php?cmd=edit&sup_uid=$sup_uid\"><IMG src=\"css/images/edit.gif\"></a></td></tr>";
                 }

                 print "</table>\n";
                 print "<br>";
                

echo "  </div>\n"; 
echo " <div class='boxbottom'><div></div></div>\n"; 
echo "</div>\n"; 
echo "\n";

echo "<br/>";

echo "<div class='box'>\n"; 
echo " <div class='boxtop'><div></div></div>\n"; 
echo "  <div class='boxcontent'>\n"; 
echo "<center><h2>Add User</h2></center>\n";
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<div align="center">
<table border="0" width="300" bordercolor="#FFFFFF">
	<tr>
		<td><b>Username:</b></td>
		<td><input type="text" name="username" size="50"></td>
	</tr>
	<tr>
		<td><b>Password:</b></td>
		<td><input type="password" name="password" size="50"></td>
	</tr>
	<tr>
		<td><b>Mail:</b></td>
		<td><input type="text" name="mail" size="50"></td>
	</tr>
	<tr>
		<td ><input type="submit" name="action" value="Send" ></td>
	</tr>
</table>
</div>
</form>
<?php
echo "  </div>\n"; 
echo " <div class='boxbottom'><div></div></div>\n"; 
echo "</div>\n"; 
echo "\n";
html_footer();
?>